<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/8
  Time: 19:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <base href="${pageContext.request.contextPath}/">
    <title>学校机房信息</title>
    <script src="jq/jquery.js"></script>
    <style>
      table tr:nth-child(even){
        background: darkgray;
      }
      a{
        text-decoration: none;
      }
    </style>
  </head>
  <body>
  <h1 align="center">学校机房管理系统</h1>
  <p align="center"><a href="add.jsp">添加机房</a></p>
    <table border="1px" align="center">
      <tr>
        <th>序号</th>
        <th>机房名称</th>
        <th>计算机数量</th>
        <th>机房管理员</th>
        <th>机房位置</th>
        <th>机房状态</th>
        <th>操作</th>
      </tr>
      <c:forEach items="${sessionScope.list}" var="computerRoom">
        <tr align="center">
          <td>${computerRoom.roomId}</td>
          <td>${computerRoom.roomName}</td>
          <td>${computerRoom.computerNumber}</td>
          <td>${computerRoom.manager}</td>
          <td>${computerRoom.location}</td>
          <td>${computerRoom.state}</td>
          <td><a href="javascript:void(0)" onclick="remove('${computerRoom.roomId}')">删除</a></td>
        </tr>
      </c:forEach>
    </table>
  </body>
  <script>
    function remove(id) {
      if(confirm("确认是否删除？")) {
        $.getJSON(
                "ComputerRoomDelete",
                {id:id},
                function (data) {
                  if (data) {
                    alert("删除成功");
                    location.href="ComputerRoomList";
                  } else {
                    alert("删除失败")
                  }
                }
        )
      }
    }
  </script>
</html>